package vn.support.core.dto;

import java.util.HashMap;
import java.util.Map;

public class DataObjectUtil {
	private Map<String, DataObject> dataObjects;
	
	private static DataObjectUtil instance;
	
	public static DataObjectUtil getInstance() {
		if(instance == null) {
			instance = new DataObjectUtil();
		}
		return instance;
	}
	
	protected DataObjectUtil() {
		this.dataObjects = new HashMap<String, DataObject>();
	}
	
	public static DataObject get(String name) {
		DataObjectUtil instance = getInstance();
		if(instance.dataObjects.containsKey(name)) {
			return instance.dataObjects.get(name);
		}
		DataObject dataObject = new DataObject(name);
		instance.dataObjects.put(name, dataObject);
		return dataObject;
	}
	
	public static void set(String name, DataObject object) {
		DataObjectUtil util = getInstance();
		util.dataObjects.put(name, object);
	}
}
